package com.yanfan.ccapi.service.impl;

import com.yanfan.ccapi.service.ICcapiUserAuthorizeService;
import com.yanfan.ccapicode.dao.UserAuthorizeRepository;
import com.yanfan.ccapicode.dao.entity.UserAuthorizeDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * 云云对接用户授权Service业务层处理
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@Service
public class CcapiUserAuthorizeServiceImpl implements ICcapiUserAuthorizeService {
    @Autowired
    private UserAuthorizeRepository ccapiUserAuthorizeMapper;

    /**
     * 查询云云对接用户授权
     *
     * @param id 云云对接用户授权主键
     * @return 云云对接用户授权
     */
    @Override
    public UserAuthorizeDO selectCcapiUserAuthorizeById(Long id) {
        return ccapiUserAuthorizeMapper.selectById(id);
    }

    /**
     * 查询云云对接用户授权列表
     *
     * @param ccapiUserAuthorize 云云对接用户授权
     * @return 云云对接用户授权
     */
    @Override
    public List<UserAuthorizeDO> selectCcapiUserAuthorizeList(UserAuthorizeDO ccapiUserAuthorize) {
        return ccapiUserAuthorizeMapper.selectCcapiUserAuthorizeList(ccapiUserAuthorize);
    }

    /**
     * 新增云云对接用户授权
     *
     * @param ccapiUserAuthorize 云云对接用户授权
     * @return 结果
     */
    @Override
    public boolean insertCcapiUserAuthorize(UserAuthorizeDO ccapiUserAuthorize) {
        ccapiUserAuthorize.setCreateTime(LocalDateTime.now());
        return ccapiUserAuthorizeMapper.insertOrUpdate(ccapiUserAuthorize);
    }

    /**
     * 修改云云对接用户授权
     *
     * @param ccapiUserAuthorize 云云对接用户授权
     * @return 结果
     */
    @Override
    public boolean updateCcapiUserAuthorize(UserAuthorizeDO ccapiUserAuthorize) {
        ccapiUserAuthorize.setUpdateTime(LocalDateTime.now());
        return ccapiUserAuthorizeMapper.insertOrUpdate(ccapiUserAuthorize);
    }

    /**
     * 批量删除云云对接用户授权
     *
     * @param ids 需要删除的云云对接用户授权主键
     * @return 结果
     */
    @Override
    public boolean deleteCcapiUserAuthorizeByIds(Long[] ids) {
        return ccapiUserAuthorizeMapper.deleteByIds(Arrays.asList(ids));
    }

    /**
     * 删除云云对接用户授权信息
     *
     * @param id 云云对接用户授权主键
     * @return 结果
     */
    @Override
    public boolean deleteCcapiUserAuthorizeById(Long id) {
        return ccapiUserAuthorizeMapper.deleteById(id);
    }
}
